﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Manager_PictureLibrary : System.Web.UI.PageEx
{
    private string strPageCode = "Q0000A";
    private string strLoginResult = string.Empty;

    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strQuery = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            DataBinds();
        }
    }
    protected void DataBinds()
    {
        DataSet ds = WebBase.Comm.SelectByPage("dbPicture", "*", strQuery, "pId", "pId", 0, 1, gridList.PageSize, gridList.PageIndex + 1, out iPageCount, out iRecordCount);
        gridList.RecordCount = iRecordCount;
        gridList.DataSource = ds;
        gridList.DataBind();
    }
    protected void gridList_RowCommand(object sender, FineUI.GridCommandEventArgs e)
    {
        int iSelectId = 0;
        Dictionary<int, Dictionary<int, string>> modifiedDict = gridList.GetModifiedDict();
        string strCommand = e.CommandName;
        int iResult = 0;
        string strResult = string.Empty;
        if (!string.IsNullOrEmpty(strCommand))
        {
            int iSelectIndexId = e.RowIndex;
            string strSelectId = gridList.Rows[iSelectIndexId].DataKeys[0].ToString();
            Int32.TryParse(strSelectId, out iSelectId);

            switch (strCommand)
            {
                case "Delete":
                    iResult = DalEx.DbPictureEx.Delete(" and pId=" + iSelectId, ref strResult);
                    break;
                case "Edit":

                    break;
            }
            if (iResult > 0)
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
                DataBinds();
            }
            else
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Warning);
            }
        } 
    }
    protected void btnSelectDelete_Click(object sender, EventArgs e)
    {
        string strResult = string.Empty;
        List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        if (lstSelectRowId.Count >= 1)
        {
            string[] SelectIdArray = new string[lstSelectRowId.Count];
            int iIndexTemp = 0;
            foreach (int iLinkId in lstSelectRowId)
                SelectIdArray[iIndexTemp] = iLinkId.ToString();
            if (DalEx.DbPictureEx.Delete(" and pId in (" + string.Join(",", SelectIdArray) + ")", ref strResult) > 0)
            {
                FineUI.Alert.Show(strResult, "信息提示", FineUI.MessageBoxIcon.Information);
                DataBinds();
            }
            else
            {
                FineUI.Alert.Show(strResult, "信息提示", FineUI.MessageBoxIcon.Error);
            }
        }
        else
        {
            FineUI.Alert.Show("请选择要删除的内容！", "信息提示", FineUI.MessageBoxIcon.Warning);
        }
    }
    protected void ttboxKeywords_Trigger1Click(object sender, EventArgs e)
    {
        ttboxKeywords.Text = string.Empty;
    }
    protected void ttboxKeywords_Trigger2Click(object sender, EventArgs e)
    {       
        strQuery = string.Empty;
        string strKeywords = SqlHelper.String(ttboxKeywords.Text.Trim());
        if (!string.IsNullOrEmpty(strKeywords))
            strQuery += " and (pTitle like '%" + strKeywords + "%' or pNote like '%" + strKeywords + "%')";
        DataBinds();
    }
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iPageSize = 20;
        int.TryParse(ddlPageSize.SelectedValue, out iPageSize);
        gridList.PageSize = iPageSize;
        DataBinds();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DataBinds();
    }
    protected void gridList_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
    {
        gridList.PageIndex = e.NewPageIndex;
        DataBinds();
    }
    protected void winForm_Close(object sender, FineUI.WindowCloseEventArgs e)
    {
        DataBinds();
    }
    protected void btnAddArticle_Click(object sender, EventArgs e)
    {
        winForm.IFrameUrl = "PictureLibraryAdd.aspx";
        winForm.IFrameName = "新增图库资料";
        winForm.Title = "新增图库资料";
        winForm.Hidden = false;
    }
}
